import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mind_your_tasks/models/Event.dart';
import 'package:mind_your_tasks/models/Task.dart';
import 'package:mind_your_tasks/models/User.dart';
import 'package:mind_your_tasks/screens/home_page.dart';
import 'package:mind_your_tasks/screens/task/add_task.dart';
import 'package:mind_your_tasks/screens/task/task_details.dart';
import 'package:mind_your_tasks/screens/task/tasks_utils.dart';
import 'package:mind_your_tasks/theme/colors/light_colors.dart';
import 'package:percent_indicator/circular_percent_indicator.dart';
import 'package:percent_indicator/linear_percent_indicator.dart';
import 'package:rflutter_alert/rflutter_alert.dart';

import '../../storage_utils.dart';
import '../../widgets/task_container.dart';

class EventHomePage extends StatefulWidget {
  EventHomePage({Key key, this.event}) : super(key: key);

  Event event;

  @override
  _EventHomePageState createState() => _EventHomePageState();

  List<Task> getTasks(Status status) {
    List<Task> tasks = [];
    event.tasks.forEach((task) {
      if (task.status == status) tasks.add(task);
    });
    return tasks;
  }
}

class _EventHomePageState extends State<EventHomePage> {
  @override
  void initState() {
    super.initState();
  }

  Future<String> getData(String eventUUID) async {
    widget.event = await StorageUtils.getEventByUUID(eventUUID);
    return "ready";
  }

  @override
  Widget build(BuildContext context) => FutureBuilder(
        initialData: false,
        future: getData(widget.event.UUID),
        builder: (context, snapshot) =>
            snapshot.connectionState == ConnectionState.done && snapshot.hasData
                ? _buildWidget(context, snapshot.data)
                : const SizedBox(),
      );

  @override
  Widget _buildWidget(BuildContext context, dynamic data) {
    double percentage = 0;
    if (widget.event.tasks.length > 0 &&
        widget.getTasks(Status.COMPLETED).length > 0) {
      percentage = (widget.getTasks(Status.COMPLETED).length /
          widget.event.tasks.length);
    }
    double width = MediaQuery.of(context).size.width;
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Color.fromRGBO(242, 243, 248, 1.0),
      systemNavigationBarColor: Colors.black45,
    ));
    return Scaffold(
      backgroundColor: Color.fromRGBO(242, 243, 248, 1.0),
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(35.0),
        child: AppBar(
          iconTheme: IconThemeData(color: Colors.black),
          backgroundColor: Color.fromRGBO(242, 243, 248, 1.0),
          elevation: 0,
          actions: <Widget>[
            Padding(
              padding: EdgeInsets.only(right: 15.0, top: 10),
              child: GestureDetector(
                onTap: () {
                  _onCloseEvent(context);
                },
                child: Icon(
                  Icons.delete,
                  color: Color.fromRGBO(189, 17, 17, 1.0),
                ),
              ),
            ),
          ],
        ),
      ),
      body: SingleChildScrollView(
        child: Container(
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
          child: Column(
            children: <Widget>[
              Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Padding(
                      padding: EdgeInsets.only(top: 10),
                      child: Text(
                        widget.event.name,
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            fontWeight: FontWeight.w700,
                            fontSize: 25,
                            color: Colors.black),
                      ),
                    )
                  ]),
              Container(
                padding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
                child: Container(
                  padding:
                      EdgeInsets.symmetric(horizontal: 15.0, vertical: 10.0),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(20),
                  ),
                  height: 280,
                  width: width,
                  child: Column(
                    children: <Widget>[
                      Row(
                        children: <Widget>[
                          Expanded(
                            flex: 60,
                            child: Padding(
                              padding: const EdgeInsets.only(left: 8, right: 8),
                              child: Column(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceEvenly,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Row(
                                    children: <Widget>[
                                      Container(
                                        height: 45,
                                        width: 2,
                                        decoration: BoxDecoration(
                                          color: Colors.green.withOpacity(0.5),
                                          borderRadius: BorderRadius.all(
                                              Radius.circular(4.0)),
                                        ),
                                      ),
                                      Padding(
                                        padding: const EdgeInsets.all(8.0),
                                        child: Column(
                                          mainAxisAlignment:
                                              MainAxisAlignment.center,
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: <Widget>[
                                            Padding(
                                              padding: const EdgeInsets.only(
                                                  left: 4, bottom: 2),
                                              child: Text(
                                                '日期',
                                                textAlign: TextAlign.center,
                                                style: TextStyle(
                                                  fontWeight: FontWeight.w600,
                                                  fontSize: 16,
                                                  letterSpacing: -0.1,
                                                  color: Color.fromRGBO(
                                                      67, 147, 31, 0.8),
                                                ),
                                              ),
                                            ),
                                            Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.center,
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.start,
                                              children: <Widget>[
                                                SizedBox(
                                                  width: 23,
                                                  height: 23,
                                                  child: Icon(
                                                    Icons.access_time,
                                                    color: Color.fromRGBO(
                                                        67, 147, 31, 0.8),
                                                    size: 20,
                                                  ),
                                                ),
                                                Padding(
                                                  padding:
                                                      const EdgeInsets.only(
                                                          left: 4, bottom: 3),
                                                  child: Text(
                                                    widget.event.date != null
                                                        ? widget
                                                                .event.date.year
                                                                .toString() +
                                                            "-" +
                                                            widget
                                                                .event.date.month
                                                                .toString() +
                                                            "-" +
                                                            widget
                                                                .event.date.day
                                                                .toString() +
                                                            " " +
                                                            widget
                                                                .event.date.hour
                                                                .toString() +
                                                            ":" +
                                                            widget.event.date
                                                                .minute
                                                                .toString()
                                                        : "未选择日期",
                                                    textAlign: TextAlign.center,
                                                    style: TextStyle(
                                                        fontWeight:
                                                            FontWeight.w600,
                                                        fontSize: 14,
                                                        color: Color.fromRGBO(
                                                            67, 147, 31, 0.8)),
                                                  ),
                                                ),
                                              ],
                                            )
                                          ],
                                        ),
                                      )
                                    ],
                                  )
                                ],
                              ),
                            ),
                          ),
                          Expanded(
                            flex: 40,
                            child: Padding(
                              padding: const EdgeInsets.only(
                                  left: 8, right: 8, top: 4),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceEvenly,
                                children: [
                                  CircularPercentIndicator(
                                    radius: 120.0,
                                    lineWidth: 10.0,
                                    animation: true,
                                    percent: percentage,
                                    center: Text(
                                      (percentage * 100).toInt().toString() +
                                          " %",
                                      style: TextStyle(
                                          fontSize: 20.0,
                                          fontWeight: FontWeight.w600,
                                          color: Colors.black),
                                    ),
                                    backgroundColor: Colors.grey[100],
                                    circularStrokeCap: CircularStrokeCap.round,
                                    progressColor:
                                        Colors.blueAccent.withOpacity(0.8),
                                  )
                                ],
                              ),
                            ),
                          ),
                        ],
                      ),
                      Padding(
                        padding: const EdgeInsets.only(
                            left: 10, right: 10, top: 18, bottom: 8),
                        child: Container(
                          height: 2,
                          decoration: BoxDecoration(
                            color: Color.fromRGBO(212, 212, 212, 1.0),
                            borderRadius:
                                BorderRadius.all(Radius.circular(4.0)),
                          ),
                        ),
                      ),
                      Padding(
                        padding: const EdgeInsets.only(
                            left: 10, right: 10, top: 18, bottom: 16),
                        child: Row(
                          children: <Widget>[
                            Expanded(
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Column(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: <Widget>[
                                      Text(
                                        '已完成',
                                        textAlign: TextAlign.center,
                                        style: TextStyle(
                                          fontWeight: FontWeight.w500,
                                          fontSize: 16,
                                          letterSpacing: -0.2,
                                          color: Colors.grey.withOpacity(0.7),
                                        ),
                                      ),
                                      Padding(
                                        padding: const EdgeInsets.only(top: 4),
                                        child: LinearPercentIndicator(
                                          animation: true,
                                          percent: widget
                                                  .getTasks(Status.COMPLETED)
                                                  .length /
                                              widget.event.tasks.length,
                                          lineHeight: 5,
                                          width: 90,
                                          linearStrokeCap:
                                              LinearStrokeCap.roundAll,
                                          backgroundColor: Colors.grey[100],
                                          progressColor:
                                              Color.fromRGBO(67, 147, 31, 1.0),
                                        ),
                                      ),
                                      Padding(
                                        padding: const EdgeInsets.only(top: 6),
                                        child: Text(
                                          widget
                                              .getTasks(Status.COMPLETED)
                                              .length
                                              .toString(),
                                          textAlign: TextAlign.center,
                                          style: TextStyle(
                                            fontWeight: FontWeight.w600,
                                            fontSize: 12,
                                            color: Colors.grey.withOpacity(0.7),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ],
                              ),
                            ),
                            Expanded(
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Column(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: <Widget>[
                                      Text(
                                        '未完成',
                                        textAlign: TextAlign.center,
                                        style: TextStyle(
                                          fontWeight: FontWeight.w500,
                                          fontSize: 16,
                                          letterSpacing: -0.2,
                                          color: Colors.grey.withOpacity(0.7),
                                        ),
                                      ),
                                      Padding(
                                        padding: const EdgeInsets.only(top: 4),
                                        child: LinearPercentIndicator(
                                          animation: true,
                                          percent: widget
                                                  .getTasks(Status.ACTIVE)
                                                  .length /
                                              widget.event.tasks.length,
                                          lineHeight: 5,
                                          width: 90,
                                          linearStrokeCap:
                                              LinearStrokeCap.roundAll,
                                          backgroundColor: Colors.grey[100],
                                          progressColor:
                                              Color.fromRGBO(246, 197, 15, 1.0),
                                        ),
                                      ),
                                      Padding(
                                        padding: const EdgeInsets.only(top: 6),
                                        child: Text(
                                          widget
                                              .getTasks(Status.ACTIVE)
                                              .length
                                              .toString(),
                                          textAlign: TextAlign.center,
                                          style: TextStyle(
                                            fontWeight: FontWeight.w600,
                                            fontSize: 12,
                                            color: Colors.grey.withOpacity(0.7),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ],
                              ),
                            ),
                            Expanded(
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Column(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: <Widget>[
                                      Text(
                                        '待办中',
                                        textAlign: TextAlign.center,
                                        style: TextStyle(
                                          fontWeight: FontWeight.w500,
                                          fontSize: 16,
                                          letterSpacing: -0.2,
                                          color: Colors.grey.withOpacity(0.7),
                                        ),
                                      ),
                                      Padding(
                                        padding: const EdgeInsets.only(top: 4),
                                        child: LinearPercentIndicator(
                                          animation: true,
                                          percent: widget
                                                  .getTasks(Status.PENDING)
                                                  .length /
                                              widget.event.tasks.length,
                                          lineHeight: 5,
                                          width: 90,
                                          linearStrokeCap:
                                              LinearStrokeCap.roundAll,
                                          backgroundColor: Colors.grey[100],
                                          progressColor:
                                              Color.fromRGBO(219, 20, 36, 1.0),
                                        ),
                                      ),
                                      Padding(
                                        padding: const EdgeInsets.only(top: 6),
                                        child: Text(
                                          widget
                                              .getTasks(Status.PENDING)
                                              .length
                                              .toString(),
                                          textAlign: TextAlign.center,
                                          style: TextStyle(
                                            fontWeight: FontWeight.w600,
                                            fontSize: 12,
                                            color: Colors.grey.withOpacity(0.7),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ],
                              ),
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(top: 10, bottom: 10),
                child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Expanded(
                        child: Text(
                          "事项列表",
                          textAlign: TextAlign.center,
                          style: TextStyle(
                              fontWeight: FontWeight.w700,
                              fontSize: 25,
                              color: Colors.black),
                        ),
                      ),
                      Expanded(
                        child: GestureDetector(
                          onTap: () => _onAddTask(context),
                          child: Icon(Icons.add_box,
                              size: 30, color: Colors.black),
                        ),
                      ),
                    ]),
              ),
              Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(0),
                  ),
                  width: width,
                  child: DefaultTabController(
                    length: 3,
                    child: Scaffold(
                      appBar: PreferredSize(
                        preferredSize: Size.fromHeight(55.0),
                        child: AppBar(
                          backgroundColor: Colors.white,
                          foregroundColor: Colors.black,
                          elevation: 0,
                          bottom: TabBar(
                            labelStyle: TextStyle(fontSize: 18),
                            labelColor: Colors.black,
                            indicatorColor: Colors.blueAccent,
                            tabs: [
                              Tab(text: "已完成"),
                              Tab(text: "未完成"),
                              Tab(text: "待办中"),
                            ],
                          ),
                        ),
                      ),
                      body: TabBarView(
                        children: [
                          showTaskList(Color.fromRGBO(67, 147, 31, 1.0),
                              widget.getTasks(Status.COMPLETED)),
                          showTaskList(Color.fromRGBO(246, 197, 15, 1.0),
                              widget.getTasks(Status.ACTIVE)),
                          showTaskList(Color.fromRGBO(219, 20, 36, 1.0),
                              widget.getTasks(Status.PENDING)),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  _buildTasks(Color color, List<Task> tasks) {
    List<Widget> list = [];
    tasks.forEach((element) {
      list.add(GestureDetector(
        onTap: () => _taskDetails(context, element),
        child: TaskContainer(
            color: color,
            taskName: element.name,
            personName: element.user != null ? element.user.username : "暂无用户",
            date: element.date != null
                ? element.date.year.toString() +
                    "-" +
                    element.date.month.toString() +
                    "-" +
                    element.date.day.toString() +
                    " " +
                    element.date.hour.toString() +
                    ":" +
                    element.date.minute.toString()
                : "未选择时间",
            desc: element.description),
      ));
    });
    if (list.isEmpty)
      list.add(Container(
        width: MediaQuery.of(context).size.width,
        child: Center(
          child: Text(
            "该分类暂无事项",
            style: TextStyle(
                color: Colors.grey,
                fontSize: 20.0,
                fontWeight: FontWeight.w500),
          ),
        ),
      ));
    return list;
  }

  showTaskList(Color color, List<Task> tasks) {
    return Container(
      padding: const EdgeInsets.only(top: 10, bottom: 65),
      color: Colors.white,
      child: ListView(
        scrollDirection: Axis.horizontal,
        children: _buildTasks(color, tasks),
      ),
    );
  }

  deleteTask(Task task) async {
    List<Task> tasks = widget.event.tasks;
    List<Task> new_tasks = [];
    tasks.forEach((element) {
      if (element.UUID != task.UUID) new_tasks.add(element);
    });
    widget.event.tasks = new_tasks;
    bool updated = await StorageUtils.updateEvent(widget.event);
  }

  _taskDeleteContent() {
    return Container(
      child: Column(
        children: [
          Text(
            "确定删除该事项?",
            style: TextStyle(color: Colors.grey, fontSize: 16),
          ),
        ],
      ),
    );
  }

  _taskDelete(context, Task task) {
    var alertStyle = AlertStyle(
      animationType: AnimationType.fromTop,
      isCloseButton: false,
      isOverlayTapDismiss: false,
      descStyle: TextStyle(fontWeight: FontWeight.normal, fontSize: 15),
      animationDuration: Duration(milliseconds: 200),
      alertBorder: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(20.0),
        side: BorderSide(
          color: Colors.white,
        ),
      ),
      titleStyle: TextStyle(
          color: Colors.red, fontSize: 22, fontWeight: FontWeight.w800),
    );

    Alert(
        context: context,
        style: alertStyle,
        type: AlertType.none,
        title: "提示",
        content: _taskDeleteContent(),
        buttons: [
          DialogButton(
            onPressed: () async =>
                {Navigator.pop(context), _taskDetails(context, task)},
            color: Colors.grey,
            child: Text(
              "取消",
              style: TextStyle(color: Colors.white, fontSize: 20),
            ),
          ),
          DialogButton(
            onPressed: () => {
              Navigator.pop(context),
              deleteTask(task),
              setState(() {}),
              ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                content: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Text("已删除",
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 16,
                              fontWeight: FontWeight.w800))
                    ]),
                backgroundColor: Colors.green,
              )),
            },
            color: Colors.red,
            child: Text(
              "删除",
              style: TextStyle(color: Colors.white, fontSize: 20),
            ),
          ),
        ]).show();
  }

  _taskDetails(context, Task task) {
    var alertStyle = TaskUtils.getAlertStyle(task.status, true, false);
    TaskDetails taskDetails = TaskDetails(task: task);

    Alert(
        context: context,
        style: alertStyle,
        type: AlertType.none,
        title: "事项详情",
        content: taskDetails,
        buttons: [
          DialogButton(
            onPressed: () => {
              Navigator.pop(context),
              _taskDelete(context, task),
            },
            color: Colors.red,
            child: Text(
              "删除",
              style: TextStyle(color: Colors.white, fontSize: 20),
            ),
          ),
          DialogButton(
            onPressed: () async => {
              task.status =
                  TaskUtils.convertStatus(taskDetails.controllerStatus.text),
              task.user = taskDetails.controllerPeople.text != ""
                  ? await StorageUtils.getUser(
                      taskDetails.controllerPeople.text)
                  : null,
              TaskUtils.updateTaskInEvent(task, widget.event),
              await StorageUtils.updateEvent(widget.event),
              Navigator.pop(context),
              setState(() {}),
              ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                content: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Text("Task correctly modified",
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 16,
                              fontWeight: FontWeight.w800))
                    ]),
                backgroundColor: Colors.green,
              )),
            },
            child: Text(
              "保存",
              style: TextStyle(color: Colors.white, fontSize: 20),
            ),
          ),
        ]).show();
  }

  _onCloseEvent(context) {
    var alertStyle = AlertStyle(
      animationType: AnimationType.fromTop,
      isCloseButton: false,
      isOverlayTapDismiss: true,
      descStyle: TextStyle(fontWeight: FontWeight.normal, fontSize: 15),
      animationDuration: Duration(milliseconds: 200),
      alertBorder: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(20.0),
        side: BorderSide(
          color: Colors.white,
        ),
      ),
      titleStyle: TextStyle(
          color: Colors.red, fontSize: 22, fontWeight: FontWeight.w800),
    );

    Alert(
        context: context,
        style: alertStyle,
        type: AlertType.none,
        title: "确认删除该事件",
        content: closeEvent(),
        buttons: [
          DialogButton(
            color: Colors.grey,
            onPressed: () => Navigator.pop(context),
            child: Text(
              "取消",
              style: TextStyle(color: Colors.white, fontSize: 14),
            ),
          ),
          DialogButton(
            color: Colors.red,
            onPressed: () => {
              widget.event.ended = true,
              StorageUtils.updateEvent(widget.event),
              Navigator.pushAndRemoveUntil(
                  context,
                  MaterialPageRoute(builder: (context) => HomePage()),
                  (route) => false),
            },
            child: Text(
              "确定",
              style: TextStyle(color: Colors.white, fontSize: 14),
            ),
          )
        ]).show();
  }

  closeEvent() {
    return Container(
      child: Column(
        children: [
          Text(
            "删除后事件下所有事项也将移除",
            style: TextStyle(color: Colors.grey, fontSize: 16),
          ),
        ],
      ),
    );
  }

  _onAddTask(context) {
    // Reusable alert style
    var alertStyle = AlertStyle(
      animationType: AnimationType.fromTop,
      isCloseButton: true,
      isOverlayTapDismiss: false,
      descStyle: TextStyle(fontWeight: FontWeight.normal, fontSize: 15),
      animationDuration: Duration(milliseconds: 200),
      alertBorder: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(20.0),
        side: BorderSide(
          color: Colors.white,
        ),
      ),
      titleStyle: TextStyle(
          color: Colors.blueAccent, fontSize: 22, fontWeight: FontWeight.w800),
    );

    // Alert dialog using custom alert style

    AddTaskPage taskPage = AddTaskPage();
    Alert(
        context: context,
        style: alertStyle,
        type: AlertType.none,
        title: "创建新事项",
        content: taskPage,
        buttons: [
          DialogButton(
            onPressed: () => {
              if (taskPage.formKey.currentState.validate())
                {
                  Navigator.pop(context),
                  setState(() {}),
                  ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                    content: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: <Widget>[
                          Text("创建成功",
                              style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 16,
                                  fontWeight: FontWeight.w800))
                        ]),
                    backgroundColor: Colors.green,
                  )),
                  createTask(taskPage),
                }
            },
            child: Text(
              "创建",
              style: TextStyle(color: Colors.white, fontSize: 20),
            ),
          )
        ]).show();
  }

  createTask(AddTaskPage taskPage) async {
    String taskName = taskPage.controllerTaskName.text;
    String username = taskPage.controllerPeople.text;
    String description = taskPage.controllerDescription.text;

    debugPrint(username);
    DateTime date = taskPage.controllerDate.text != ""
        ? DateTime.parse(taskPage.controllerDate.text)
        : null;

    User user = username != "" ? await StorageUtils.getUser(username) : null;
    Task task = Task(taskName, date, user, description);
    widget.event.tasks.add(task);
    bool updated = await StorageUtils.updateEvent(widget.event);
  }

  Text subheading(String title) {
    return Text(
      title,
      style: TextStyle(
          color: LightColors.kDarkBlue,
          fontSize: 20.0,
          fontWeight: FontWeight.w700,
          letterSpacing: 1.2),
    );
  }
}
